import webpack from 'webpack'
import path from 'path'

const isRelease = process.env.APP_ENV === 'release';
const isProd = process.env.NODE_ENV === 'production';
const version = process.env.npm_package_version

const extNodeModules = {}
const extMods = ['node-fetch']
extMods.forEach(i => {
    extNodeModules[i] = "commonjs " + i
})

export default {
    entry: {
        'account-sdk': "./src/index.js"
    },
    output: {
        path: isRelease ? path.resolve('./release', version) : path.resolve('./dist'),
        filename: '[name].js',
        libraryTarget: 'umd'
    },
    // devtool: isProd ? false : 'source-map',
    watch: !isProd,
    resolve: {
        modules: [
            path.join(__dirname, './src'),
            'node_modules'
        ]
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                use: ['babel-loader']
            }
        ]
    },
    externals: extNodeModules,
    plugins: [
        new webpack.DefinePlugin({
            "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
        })
    ]
}